package com.lzh.dlykserver.controller;

import com.lzh.dlykserver.DlykServerApplication;
import com.lzh.dlykserver.entity.TActivity;
import com.lzh.dlykserver.entity.TDicValue;
import com.lzh.dlykserver.entity.TProduct;
import com.lzh.dlykserver.result.DicEnum;
import com.lzh.dlykserver.result.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DicController {

    /**
     * 获取字典数据
     * @param typeCode
     * @return
     */
    @GetMapping("/api/dicvalue/{typeCode}")
    public R dicData(@PathVariable("typeCode") String typeCode) {
        if (typeCode.equals(DicEnum.ACTIVITY.getCode())) {
            List<TActivity> tActivityListList = (List<TActivity>) DlykServerApplication.cacheMap.get(typeCode);
            return R.OK(tActivityListList);
        } else if (typeCode.equals(DicEnum.PRODUCT.getCode())) {
            List<TProduct> tTProductListList = (List<TProduct>) DlykServerApplication.cacheMap.get(typeCode);
            return R.OK(tTProductListList);
        } else {
            List<TDicValue> tDicValueList = (List<TDicValue>) DlykServerApplication.cacheMap.get(typeCode);
            return R.OK(tDicValueList);
        }
    }
}
